#include "panic.h"

//#define BROKEN_HEART

void kernel_panic (const char *error) {
	setTextColor (0x4); // Rot
#ifdef BROKEN_HEART
	print ("\n");
	print ("                                           ..^^^.\n");
	print ("                                         ,/#######;.\n");
	print ("                                       -%###########%,\n");
	print ("                                      -@######%  $###@-\n");
	print ("                       ..--.         -M#######$   $###M;\n");
	print ("                    ,:$M####CX;     ,;##########$;}O###X=\n");
	print ("                  ,/@###########=      ;################-\n");
	print ("                 -+##############/,      %##############-\n");
	print ("                 %M###############=      /##############.\n");
	print ("                M#################      .M#############:.\n");
	print ("                e################M      .e###########M:.\n");
	print ("                x#################.      -$-x#######e:\n");
	print ("                 /e##################%-     -######$-\n");
	print ("                 .;##################x     .x#####+.\n");
	print ("                  .;x################/     -x####-.\n");
	print ("                    .:x##############,       .MM/\n");
	print ("                       .:-$############$-    .$$-\n");
	print ("                            .,-=:+$e###x:    ./=.\n");
	print ("                                    ./x$:    -:,\n");
	print ("                                     ./$      .$\n");
	print ("                                      .        .\n");
	print ("'you broke my heart and torn it into pieces'   -   GlaDOS\n");
#endif
	printf ("\nError: %s", error);

	asm volatile ("cli"); // Aufhängen
	while (1) {
		asm ("hlt");
	}
}

void dump_process_core (struct stack_frame *sf) {
	printf ("EAX: 0x%08x EBX: 0x%08x ECX: 0x%08x EDX: 0x%08x\n", sf->eax, sf->ebx, sf->ecx, sf->edx);
	printf ("EDI: 0x%08x ESI: 0x%08x EBP: 0x%08x ESP: 0x%08x\n", sf->edi, sf->esi, sf->ebp, sf->_esp);
	printf ("EIP: 0x%08x\n", sf->eip);
	printf ("GS : 0x%08x FS : 0x%08x ES : 0x%08x DS : 0x%08x\n", sf->gs, sf->fs, sf->es, sf->ds);
	printf ("CS : 0x%08x EF : 0x%08x SS : 0x%08x\n", sf->cs, sf->eflags, sf->ss);
	printf ("Interrupt: %02x Error: %04x\n", sf->interrupt, sf->error);
}